package cn.edu.ctbu.yrx.dao;

import cn.edu.ctbu.yrx.entity.Student;
import cn.edu.ctbu.yrx.entity.Teacher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentRepository extends JpaRepository<Student, Integer> {

    void deleteAllByIdInBatch(Iterable<Integer> ids);
    //public List<Student> findByName(String stuName);

    // 自定义查询方法，使用JOIN FETCH加载用户信息
    @Query("SELECT s FROM students s JOIN FETCH s.user")
    List<Student> findAllWithUser();

    @Query("SELECT s FROM students s JOIN FETCH s.user")
    Page<Student> findAllWithUser(Pageable pageable);

    @Query("SELECT t FROM students t WHERE t.user.userId = :userId")
    Student findByUserId(@Param("userId") Integer userId);

}
